<!--
 * @Description: 回弹仪维护
 * @Author: wangwangwang
 * @Date: 2020-09-21 14:09:06
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-12-29 14:20:51
-->
<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main style="display: flex">
        <div>
          <div class="header_right" @click="showCardNav = !showCardNav">
            <div class="title">搜索</div>
            <div>
              <transition name="from"></transition>
              <span v-show="!showCardNav">
                <i style="margin-right: 5px" class="el-icon-arrow-down"></i>
              </span>
              <transition name="to"></transition>
              <span v-show="showCardNav">
                <i style="margin-right: 5px" class="el-icon-arrow-up"></i>
              </span>
            </div>
          </div>
          <div v-show="showCardNav" class="hr"></div>
          <el-collapse-transition>
            <div v-show="showCardNav">
              <div class="search">
                <span style="display: inline-block;margin-bottom: 10px;">
                  <span style="margin-right: 12px">编号</span>
                  <el-input v-model="tableParam.facilityName" style="width: 170px" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
                </span>
                <span style="margin-left: 24px">
                  <span style="margin-right: 12px">设备自编码</span>
                  <el-input v-model="tableParam.code" style="width: 170px" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
                </span>
                <span style="margin-left: 24px">
                  <span style="margin-right: 12px">所属单位</span>
                  <el-input v-model="tableParam.company" style="width: 170px" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
                </span>
                <span style="margin-left: 24px">
                  <span style="margin-right: 12px">设备类型</span>
                  <el-select v-model="tableParam.facilityType" placeholder="请选择" clearable style="width: 140px">
                    <el-option label="智能回弹仪" value="1"></el-option>
                    <el-option label="普通回弹仪" value="2"></el-option>
                  </el-select>
                </span>
                <el-button icon="el-icon-search" size="medium" class="bottom_all" @click="(tableParam.page = 1), gettableData()">查 询</el-button>
                <el-button size="medium" class="bottom_all_two" style="margin-left: 12px" @click="init()">重 置</el-button>
              </div>
            </div>
          </el-collapse-transition>
          <div class="hr"></div>
          <div class="card">
            <div class="card_nav">
              <div>
                <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='TIANJIA'))!==-1" size="small" class="bottom_all" style="margin-left: 0" @click="addFromDate('添加')">
                  <i class="icon iconfont iconicon_button_add" style="font-size: 12px"></i>
                  添加
                </el-button>
                <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='RIYONG'))!==-1" size="small" class="bottom_three" @click="Update(1)">
                  <i class="icon iconfont iconicon_button_startuse" style="font-size: 12px"></i>
                  启用
                </el-button>
                <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='JINYONG'))!==-1" size="small" class="bottom_four" @click="Update(0)">
                  <i class="icon iconfont iconicon_button_disable1" style="font-size: 12px"></i>
                  禁用
                </el-button>
                <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='HTXZSZ'))!==-1" size="small" class="bottom_four" @click="open('dialog1', '')">
                  回弹限制设置
                </el-button>
                <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='HTXSSZ'))!==-1" size="small" class="bottom_four" @click="open('dialog2','')">
                  回弹系数设置
                </el-button>
              </div>
              <div>
                <el-dropdown :hide-on-click="false" trigger="click" style="margin: 0 20px">
                  <el-link :underline="false">
                    <span class="el-icon--left">
                      <i class="iconfont iconicon_button_filtrate"></i>
                    </span>
                    筛选
                  </el-link>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item v-for="(item, index) in table" :key="index">
                      <el-checkbox v-model="item.status">{{
                        item.label
                        }}</el-checkbox>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
                <el-link v-if="ButtonList.findIndex(res=>(res.buttonValue=='DAOCHU'))!==-1" :underline="false" @click="load()">
                  <span class="el-icon--left">
                    <i class="iconfont iconicon_button_export1"></i>
                  </span>
                  导出
                </el-link>
              </div>
            </div>
            <div v-loading="tableLoading" class="card_info" :style="style">
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="tableData" tooltip-effect="dark" @selection-change="handleSelectionChange">
                <el-table-column align="center" type="selection"></el-table-column>
                <template v-for="(item, index2) in table">
                  <el-table-column v-if="item.status" :key="index2" :label="item.label" align="center" :min-width="item.width" :fixed="item.label =='操作'?'right':false">
                    <template slot-scope="scope">
                      <span v-if="item.label == '状态'">
                        <span v-if="scope.row.enable == 0" style="color: #969799">禁用</span>
                        <span v-if="scope.row.enable == 1" style="color: #00a754">启用</span>
                      </span>
                      <span v-if="item.label == '设备类型'">
                        {{scope.row.facilityType==1?'智能回弹仪':scope.row.facilityType==2?'普通回弹仪':''}}
                      </span>
                      <span v-if="item.prop=='equipmentCategory'">
                        {{['','朗睿HT325', '乐陵ZC3-B', '博远HT225S'][scope.row.equipmentCategory]}}
                      </span>
                      <el-button v-else-if="item.label == '操作'&&ButtonList.findIndex(res=>(res.buttonValue=='XIUGAI'))!==-1" class="bottom_one" size="mini" @click="updateFromDate(scope.row, '修改')">

                        修改
                      </el-button>
                      <el-button v-else-if="item.label == '率定历史'" class="bottom_one" size="mini" @click="open('dialog3',scope.row)">
                        查看
                      </el-button>
                      <span v-else>{{ scope.row[item.prop] }}</span>
                    </template>
                  </el-table-column>
                </template>
              </el-table>
            </div>
          </div>
        </div>
      </el-main>
      <div class="card_bottom">
        <div class="card_bottom_left">
          <div class="top_page_totle">总共{{ total }}条</div>
          <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" :page-sizes="[10, 20, 30, 40,50,100,200,500,1000]" layout="prev,pager,sizes,next,jumper" :total="total" @size-change="sizeChange" @current-change="gettableData()"></el-pagination>
        </div>
        <div>
          <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData">刷新</el-button>
        </div>
      </div>
    </el-container>
    <!-- 添加修改 -->
    <el-dialog v-dialogDrag :visible.sync="addDialog" width="480px" :close-on-click-modal="false" :before-close="resetFromDate">
      <span slot="title" class="dialog-title">{{ addDialogTitle }}</span>
      <div class="dialoginfo">
        <el-form ref="reffromDate" :rules="rules" :inline="true" :model="fromDate" label-width="110px">
          <el-form-item prop="companyId">
            <span slot="label" style="color: #ff0000">所属单位</span>
            <el-select ref="selection1" v-model="fromDate.companyId" placeholder="请选择" @change="$nextTick(()=>{fromDate.company = $refs.selection1.selectedLabel})">
              <el-option v-for="(item, index) in companylist" :key="index" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="equipmentCategory">
            <span slot="label" style="color: #ff0000">设备类别</span>
            <el-select v-model="fromDate.equipmentCategory" placeholder="请选择">
              <el-option label="朗睿HT325" :value="1"></el-option>
              <el-option label="乐陵ZC3-B" :value="2"></el-option>
              <el-option label="博远HT225S" :value="3"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="facilityName">
            <span slot="label" style="color: #ff0000">编号</span>
            <el-input v-model="fromDate.facilityName" placeholder="请输入" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <span slot="label">物理地址</span>
            <el-input v-model="fromDate.site" placeholder="请输入" clearable></el-input>
          </el-form-item>
          <el-form-item prop="facilityType">
            <span slot="label" style="color: #ff0000">设备类型</span>
            <el-select v-model="fromDate.facilityType" placeholder="请选择">
              <el-option label="智能回弹仪" value="1"></el-option>
              <el-option label="普通回弹仪" value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <span slot="label">状态</span>
            <el-radio-group v-model="fromDate.enable">
              <el-radio :label="1">启用</el-radio>
              <el-radio :label="0">禁用</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="resetFromDate">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="pagessubmitFromDate()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 回弹限制设置 -->
    <el-dialog v-dialogDrag :visible.sync="dialog1" width="480px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">回弹限制设置</span>
      <div class="dialoginfo">
        <el-form ref="reffrom1" :inline="true" :model="from1" label-width="110px">
          <el-form-item prop="companyId">
            <span slot="label" style="color: #ff0000">公司</span>
            <el-select v-model="from1.companyId" style="width: 240px;" placeholder="请选择" @change="open('dialog1', '')">
              <el-option v-for="item in companylist" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <span slot="label" style="color: #ff0000">上限值</span>
            <el-input v-model="from1.upperLimit" placeholder="请输入" clearable></el-input>
          </el-form-item>
          <el-form-item>
            <span slot="label" style="color: #ff0000">下限值</span>
            <el-input v-model="from1.lowerLimit" placeholder="请输入" clearable></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="dialog1=false">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="submit1()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 回弹系数设置 -->
    <el-dialog v-dialogDrag :visible.sync="dialog2" width="680px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">回弹系数设置</span>
      <div style="margin-bottom:10px;">
        <span style="margin-left: 24px;margin-bottom:10px;">
          <span style="margin-right: 12px;">公司</span>
          <el-select v-model="companyId" style="width: 240px;" placeholder="请选择" @change="open('dialog2', '')">
            <el-option v-for="item in companylist" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </span>
      </div>
      <div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="table2" tooltip-effect="dark">
          <el-table-column align="center" label="检测依据" prop="name"></el-table-column>
          <el-table-column align="center" label="系数a" prop="coefficientA">
            <template slot-scope="scope">
              <el-input v-model="scope.row.coefficientA" style="width:100%"></el-input>
            </template>
          </el-table-column>
          <el-table-column align="center" label="系数b" prop="coefficientB">
            <template slot-scope="scope">
              <el-input v-model="scope.row.coefficientB" style="width:100%"></el-input>
            </template>
          </el-table-column>
          <el-table-column align="center" label="系数c" prop="coefficientC">
            <template slot-scope="scope">
              <el-input v-model="scope.row.coefficientC" style="width:100%"></el-input>
            </template>
          </el-table-column>
          <el-table-column align="center" label="系数k" prop="coefficientK">
            <template slot-scope="scope">
              <el-input v-model="scope.row.coefficientK" style="width:100%"></el-input>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="dialog2=false">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="submit2()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 率定历史 -->
    <el-dialog v-dialogDrag :visible.sync="dialog3" width="1080px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">回弹率定</span>
      <div class="dialogOtherinfo">
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width:100%" :data="table3" tooltip-effect="dark">
          <el-table-column prop="sortNum" label="序号" width="50" align="center"></el-table-column>
          <el-table-column prop="zeroDegrees" label="0°率定记录值" width="auto" align="center"></el-table-column>
          <el-table-column prop="zeroDegreesMean" label="0°均值" width="auto" align="center"></el-table-column>
          <el-table-column prop="ninetyDegrees" label="90°率定记录值" width="auto" align="center"></el-table-column>
          <el-table-column prop="ninetyDegreesMean" label="90°均值" width="auto" align="center"></el-table-column>
          <el-table-column prop="oneHundredAndEighty" label="180°率定记录值" width="auto" align="center"></el-table-column>
          <el-table-column prop="oneHundredAndEightyMean" label="180°均值" width="auto" align="center"></el-table-column>
          <el-table-column prop="twoHundredAndSeventy" label="270°率定记录值" width="auto" align="center"></el-table-column>
          <el-table-column prop="twoHundredAndSeventyMean" label="270°均值" width="auto" align="center"></el-table-column>
          <el-table-column prop="result" label="率定结果" width="auto" align="center"></el-table-column>
          <el-table-column prop="updateTime" label="更新时间" width="auto" align="center"></el-table-column>
        </el-table>
        <div style="display:flex;align-items: center;justify-content: space-between;">
          <el-pagination :current-page.sync="tableParam3.page" :page-size="tableParam3.pageSize" layout="prev, pager, next, jumper" :total="total3" @current-change="gettable3()"></el-pagination>
          <span class="top_page_totle">总共{{ total3 }}条</span>
        </div>

      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="dialog3=false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";
import {
  queryPage,
  batchUpdateOrDelete,
  saveOrUpdate,
  Download,
  jjgqueryPage,
  getLimit,
  setLimit,
  getJJGconefficient,
  setJJGconefficient,
} from "@/api/basicConfig/springback.js";
import { getDicType } from "@/api/common.js";
import { permissionsCompanyList } from "@/api/common.js";
export default {
  mixins: [mixin],
  data() {
    return {
      companyId: '',
      /*表格增删改查及下载接口*/
      queryPage: queryPage,
      batchUpdateOrDelete: batchUpdateOrDelete,
      saveOrUpdate: saveOrUpdate,
      DownloadURL: Download,
      /*表格数据*/
      table: [
        { label: "设备编号", width: "140", prop: "code", status: true },
        { label: "所属单位", width: "160", prop: "company", status: true },
        { label: "设备类别", width: "160", prop: "equipmentCategory", status: true },
        {
          label: "编号",
          width: "160",
          prop: "facilityName",
          status: true,
        },
        { label: "物理地址", width: "120", prop: "site", status: true },
        { label: "率定历史", width: "120", prop: "", status: true },
        { label: "设备类型", width: "120", prop: "", status: true },
        { label: "状态", width: "100", prop: "", status: true },
        { label: "更新时间", width: "160", prop: "updateTime", status: true },
        { label: "操作", width: "120", prop: "", status: true },
      ],
      pagesType: 0,
      companylist: [],
      /*添加表单数据*/
      rules: {
        code: [{ required: true, message: "请输入站点编码", trigger: "blur" }],
        companyId: [
          { required: true, message: "请选择单位", trigger: "change" },
        ],
        facilityName: [
          { required: true, message: "请输入编号", trigger: "blur" },
        ],
        equipmentCategory: [
          { required: true, message: "请选择设备类型", trigger: "blur" },
        ],
        facilityType: [
          { required: true, message: "请选择设备类型", trigger: "change" },
        ],
      },
      fromDate: {
        code: "",
        companyId: "",
        facilityName: "",
        equipmentCategory: '',
        facilityType: "",
        site: "",
        enable: 1,
      },
      /*回弹限制设置*/
      dialog1: false,
      from1: { companyId: '', lowerLimit: '', upperLimit: '' },
      rules1: {
        lowerLimit: [
          { required: true, message: "请输入下限值", trigger: "blur" },
        ],
        upperLimit: [
          { required: true, message: "请输入上限值", trigger: "change" },
        ],
        companyId: [
          { required: true, message: "请选择公司", trigger: "change" },
        ],
      },
      /*回弹系数设置*/
      dialog2: false,
      table2: [],
      /*率定历史*/
      dialog3: false,
      table3: [],
      tableParam3: {
        page: 1,
        pageSize: 10,
      },
      total3: 0,
      low: "",
    };
  },
  async created() {
    this.companylist = await permissionsCompanyList()
    this.tableParam = {
      ...this.tableParam,
      facilityName: "",
      equipmentCategory: '',
      code: "",
    };
    this.gettableData();
  },
  methods: {
    /*重置数据*/
    init() {
      this.tableParam.facilityName = "";
      this.tableParam.equipmentCategory = "",
      this.tableParam.code = "";
      this.gettableData();
    },
    /**
     * @param {string}  key  -弹窗名
     * @param {Object}  low  - 本条数据
     * @method  保存限制值
     **/
    async open(key, low) {
      this[key] = true;
      this.low = low;
      if (key == "dialog1") {
        console.log(getLimit);
        getLimit({ companyId: this.from1.companyId }).then((res) => {
          this.from1.lowerLimit = res.data.lowerLimit;
          this.from1.upperLimit = res.data.upperLimit;
        });
      }
      if (key == "dialog2") {
        let arr1 = [];
        let arr2 = [];
        await getJJGconefficient({ companyId: this.companyId }).then((res) => {
          arr1 = res.data;
          console.log(arr1);
        });
        await getDicType({ code: "gist" }).then((res) => {
          arr2 = res.data.items;
        });
        arr2 = arr2.map((res) => {
          let obj = arr1.find((item) => item.gistId == res.id);
          let obj1 = {};
          if (obj) {
            obj1.coefficientA = obj.coefficientA;
            obj1.coefficientB = obj.coefficientB;
            obj1.coefficientC = obj.coefficientC;
            obj1.coefficientK = obj.coefficientK;
          }
          obj1.gistId = res.id;
          obj1.name = res.itemName;
          return obj1;
        });
        this.table2 = arr2;
        console.log(arr2);
      }
      if (key == "dialog3") {
        this.gettable3();
      }
    },
    /**
     * @method  保存限制值
     **/
    submit1() {
      setLimit(this.from1).then((res) => {
        if (res.code * 1 === 1001) {
          this.$message.success('设置成功！！！')
          this.dialog1 = false;
        }
      });
    },
    /**
     * @method  保存限制值
     **/
    submit2() {
      this.table2.forEach((v) => {
        v.companyId = this.companyId
      })
      setJJGconefficient(this.table2).then((res) => {
        if (res.code * 1 === 1001) {
          this.$message.success('保存限制值成功！！！')
          this.dialog2 = false;
        }
      });
    },
    /*率定历史*/
    gettable3() {
      this.tableParam3.jjgId = this.low.id;
      jjgqueryPage(this.tableParam3).then((res) => {
        this.table3 = res.data.data;
        this.total3 = res.data.totalRows;
      });
    },
    /*保存修改*/
    pagessubmitFromDate() {
      let _this = this;
      _this.$refs.reffromDate.validate((valid) => {
        if (valid) {
          _this.submitFromDate();
        } else {
          return false;
        }
      });
    },
    sizeChange(value) {
      this.tableParam.pageSize = value;
      this.gettableData();
    }
  },
};
</script>

<style lang="scss" scoped>
.el-input,
.el-select {
  width: 240px;
}
.dialogOtherinfo {
  .el-pagination {
    padding: 10px 0;
  }
  min-height: 530px;
  .el-input,
  .el-select {
    width: 375px;
  }
}
/*
 <el-link class="table_link" :underline="false">查看配合比</el-link>*/
.table_link {
  margin: 0 10px;
  color: $bg_color;
  cursor: pointer;
}

.table_link:hover {
  opacity: 0.8;
}
</style>
